{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 四大参数\n",
    "- 普通参数\n",
    "- 默认参数\n",
    "- 关键字参数\n",
    "- 收集参数\n",
    "## 关键字参数\n",
    "- 语法\n",
    "        \n",
    "        def func(p1=v1,p2=v2......):\n",
    "            func_body\n",
    "            \n",
    "         调用参数：\n",
    "         func(p1=value1,p2=value2......)\n",
    "- 比较麻烦，但也有好处\n",
    "    - 不容易混淆，一般的实参和形参只是按照位置一一对应即可，容易出错\n",
    "    - 使用关键字参数，可以不用考虑参数的位置\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "I am a student\n",
      "My name is jingjing,i am 19 years old, adddress :天堂路12号\n",
      "I am a student\n",
      "My name is jingjing,i am 19 years old, adddress :天堂路12号\n"
     ]
    }
   ],
   "source": [
    "# 关键字参数\n",
    "def stu(name,age,addr):\n",
    "    print(\"I am a student\")\n",
    "    print(\"My name is {0},i am {1} years old, adddress :{2}\".format(name,age,addr))\n",
    "\n",
    "    \n",
    "n = \"jingjing\"    \n",
    "a = 19\n",
    "addr = \"天堂路12号\"\n",
    "\n",
    "# 普通传参数 \n",
    "stu(n,a,addr)\n",
    "\n",
    "\n",
    "# 位置调换传参数 \n",
    "def stu_key(name,age,addr):\n",
    "    print(\"I am a student\")\n",
    "    print(\"My name is {0},i am {1} years old, adddress :{2}\".format(name,age,addr))\n",
    "\n",
    "stu_key(age = a,name = n ,addr = addr)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 收集参数\n",
    "- 把没有位置，不能喝定义是的参数位置相对应的参数，放入一个特定的数据结构\n",
    "- 语法\n",
    "        \n",
    "        def func(*args):\n",
    "            func_body\n",
    "            按照list使方式访问args的传入参数\n",
    "            \n",
    "        调用：\n",
    "        func(p1,p2,p3....)\n",
    "- 收集参数可以和其它参数gongcun\n",
    "- 参数名args前需写星号 *\n",
    "- 参数名args不是必需这么写，但是我们推荐agrs，约定俗成"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'tuple'>\n",
      "jingjing\n",
      "18\n",
      "趟趟路89号\n",
      "单身\n",
      "<class 'tuple'>\n",
      "大牛\n",
      "<class 'tuple'>\n"
     ]
    }
   ],
   "source": [
    "# 收集参数示例\n",
    "def stu( *args):\n",
    "    print(type(args))\n",
    "    for item in args:\n",
    "        print(item)\n",
    "\n",
    "stu(\"jingjing\",18,\"趟趟路89号\",\"单身\")\n",
    "stu(\"大牛\")\n",
    "stu()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
